<?php
class  Employer_Model_DbTable_Job  extends  Model_DbTable_Common
{
    protected $_name = 'job' ;
	
    public function thunghiem(){
   		return "thunghiem function";		
    }
	
	public function validateJobOwner($jobId, $employerId){
		try {
	    	$sql = 'Select count(*) as permission, status from job where id = ? and employer_id = ?';
	    	$db = $this->_db;
	    	$db->setFetchMode ( Zend_Db::FETCH_ASSOC );
	    	$result = $db->fetchAll ( $sql , array($jobId, $employerId));			
	    	return $result;
    	} catch ( Exception $ex ) {
    		Echo ("<br /> Can not get final id, error: " . $ex->getMessage ());
    		exit ();
    	}
	}
	
	public function removeJob($employerId){
		try {
			$this->delete ( 'employer_id = '.$employerId.' And status = 0');
		} catch ( Exception $ex ) {
			// echo 'Caught exception: ', $e->getMessage(), "\n";
			echo ("Can not delete unnessary job. <br/> Error ".$ex->getMessage());
			exit ();
		}
	}
	
	public function getStatus($jobId){
		try {
			$sql = 'Select status from job where id = ?';
	    	$db = $this->_db;
	    	$db->setFetchMode ( Zend_Db::FETCH_ASSOC );
	    	$result = $db->fetchAll ( $sql , array($jobId));			
	    	return $result;
		} catch ( Exception $ex ) {			
			echo ("Can not get status from Job table. <br/> Error ".$ex->getMessage());
			exit ();
		}
	}
	
	public function updateStatus($status, $jobId){		
		try {
			$sql = 'update job set status = ?  where id = ?';
			$db = Zend_Db_Table_Abstract::getDefaultAdapter ();
			$db->query ( $sql ,array($status, $jobId));
		} catch ( Exception $ex ) {
			echo "Error: " . $ex->getMessage ();
			exit ();
		}
	}
	
	
}
